package org.price.sql.repo.session.core;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

import org.apache.log4j.Logger;
import org.price.sql.repo.session.db.dialect.Dialect;
import org.price.sql.repo.session.db.dialect.DialectH2;

public class DialectDetector {
    public static final Logger LOG = Logger.getLogger(DialectDetector.class);

    public DialectDetector() {

    }

    public Dialect getDialect(Connection conn) throws SQLException {
        DatabaseMetaData metadata = conn.getMetaData();

        if ("h2".equalsIgnoreCase(metadata.getDatabaseProductName())) {
            LOG.info("H2 Dialect detected.");
            return new DialectH2(conn);
        }

        return null;
    }
}
